﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Reflection;
using System.IO;

namespace Treasures
{
    public class AdvButton : BaseElement
    {
        #region Fields and Props

        public Bitmap[] BM { get; private set; }

        public Point Location { get; set; }

        public Size Size { get; set; }

        public int CurrentBitmap { get; set; }

        public static string[] BitmapPath { get; protected set; }

        #endregion

        #region ctors

        static AdvButton()
        {
            BitmapPath = new string[]
            {
                 @"res\Reset\Reset_clear.png", 
                 @"res\Reset\Reset_outlined.png"
            };
        }

        public AdvButton()
            : base()
        {
            this.BM = new Bitmap[2];
            this.BM[0] = new Bitmap(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), BitmapPath[0]));
            this.BM[1] = new Bitmap(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), BitmapPath[1]));
            this.BM[0].MakeTransparent();
            this.BM[1].MakeTransparent();
            this.FigureBitmap = BM[0];
            this.CurrentBitmap = 0;
            this.Size = FigureBitmap.Size;
            this.Scale = 1;
        }

        #endregion

        #region public methods

        public override void DrawElementFigure(Graphics g, int x, int y)
        {
            FigureBitmap = BM[CurrentBitmap];
            if (this.FigureBitmap != null)
            {
                g.DrawImage(this.FigureBitmap, new Rectangle(x, y, (int)(this.FigureBitmap.Size.Width * Scale), (int)(this.FigureBitmap.Size.Height * Scale)), 0, 0, this.FigureBitmap.Size.Width, this.FigureBitmap.Size.Height, GraphicsUnit.Pixel);
            }
            else
            {
                throw new IOException("File not found or cant be read. FigureBitmap is null.");
            }
        }

        public override object Clone()
        {
            AdvButton ret = new AdvButton();
            return ret;
        }

        #endregion
    }


}
